#include "SunMoonView.h"
#include "lvgl/lvgl.h"

// 图片资源
extern "C" {
	LV_IMG_DECLARE(ui_img_daylight);
	LV_IMG_DECLARE(ui_img_time);
	LV_IMG_DECLARE(ui_img_sunset);
	LV_IMG_DECLARE(ui_img_wether_p1_value_png);
	LV_IMG_DECLARE(ui_img_wether_p1_total_calories_png);
	LV_IMG_DECLARE(ui_img_wether_p1_third_png);
	LV_IMG_DECLARE(ui_img_wether_p1_summary_datafield_png);
	LV_IMG_DECLARE(ui_img_wether_p1_subtitle_png);
	LV_IMG_DECLARE(ui_img_wether_p1_pm_png);
	LV_IMG_DECLARE(ui_img_wether_p1_item2_png);
	LV_IMG_DECLARE(ui_img_wether_p1_icon_png);
	LV_IMG_DECLARE(ui_img_wether_p1_group_3186_png);
	LV_IMG_DECLARE(ui_img_wether_p1_basic_png);
	LV_IMG_DECLARE(ui_img_wether_p1_basic_data_item_png);
	LV_IMG_DECLARE(ui_img_wether_p1_am_png);
}

void SunMoonView::Create(lv_obj_t* body) {
	
	// 容器
	lv_obj_t* div = lv_obj_create(body);
	lv_obj_set_size(div, 260, 508);
	lv_obj_set_pos(div, 0, -19);
	lv_obj_set_align(div, LV_ALIGN_CENTER);
	lv_obj_set_scroll_dir(div, LV_DIR_VER);
	lv_obj_set_style_bg_opa(div, 8, LV_PART_MAIN);

	// 设置滚动条样式
	lv_obj_set_style_width(div, 6, LV_PART_SCROLLBAR);
	lv_obj_set_style_radius(div, 3, LV_PART_SCROLLBAR); // 圆角
	lv_obj_set_style_bg_color(div, lv_color_hex(0x101418), LV_PART_SCROLLBAR);

	CreateWweather(div);

	CreateInfoList(div);
}

void SunMoonView::CreateWweather(lv_obj_t* parent) {
	lv_obj_t* ui_P1 = lv_obj_create(parent);
	lv_obj_set_size(ui_P1, 232, 240);
	lv_obj_set_pos(ui_P1, 0, -94);
	lv_obj_set_align(ui_P1, LV_ALIGN_CENTER);
	lv_obj_clear_flag(ui_P1, LV_OBJ_FLAG_SCROLLABLE);
	lv_obj_set_style_bg_color(ui_P1, lv_color_black(), LV_PART_MAIN);
	lv_obj_set_style_bg_opa(ui_P1, 8, LV_PART_MAIN);
	lv_obj_set_style_bg_img_src(ui_P1, &ui_img_wether_p1_basic_png, LV_PART_MAIN);

	struct {
		const lv_img_dsc_t* img_src;
		int pos_x, pos_y;
	} arry[] = {
		{&ui_img_wether_p1_total_calories_png, 0, -65},{&ui_img_wether_p1_icon_png, -50, -25}, {&ui_img_sunset, 50, -25},
		{&ui_img_wether_p1_value_png, -53, 10},{&ui_img_time, 50, 10},{&ui_img_wether_p1_am_png, -54, 40},
		{&ui_img_wether_p1_pm_png, 50, 40},{&ui_img_wether_p1_group_3186_png, 0, 77}
	};

	for (uint8_t i=0;i<sizeof(arry)/sizeof(arry[0]);i++)
	{
		lv_obj_t* img = lv_img_create(ui_P1);
		lv_img_set_src(img, arry[i].img_src);
		lv_obj_set_size(img, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
		lv_obj_set_pos(img, arry[i].pos_x, arry[i].pos_y);
		lv_obj_set_align(img, LV_ALIGN_CENTER);
		lv_obj_clear_flag(img, LV_OBJ_FLAG_SCROLLABLE);
	}
}

void SunMoonView::CreateInfoList(lv_obj_t* parent) {

	struct {
		const lv_img_dsc_t* img_src;
		uint32_t pos_x, pos_y;
	} arry[] = {
		{&ui_img_daylight, 0, 49},{&ui_img_wether_p1_basic_data_item_png, 0, 100}, {&ui_img_wether_p1_summary_datafield_png, 0, 183},
		{&ui_img_wether_p1_subtitle_png, 0, 257},{&ui_img_time, 50, 10},{&ui_img_wether_p1_third_png, 0, 299},
		{&ui_img_wether_p1_item2_png, 0, 343}
	};

	for (uint8_t i = 0; i < sizeof(arry) / sizeof(arry[0]); i++)
	{
		lv_obj_t* img = lv_img_create(parent);
		lv_img_set_src(img, arry[i].img_src);
		lv_obj_set_size(img, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
		lv_obj_set_pos(img, arry[i].pos_x, arry[i].pos_y);
		lv_obj_set_align(img, LV_ALIGN_CENTER);
		lv_obj_clear_flag(img, LV_OBJ_FLAG_SCROLLABLE);
	}
}